package com.mjlf.hometeach.common.db.assit;

import com.mjlf.hometeach.common.db.provider.assit.ClassifyProvider;
import com.mjlf.hometeach.common.entity.assit.Classify;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * @auther a123
 * @create 2018-05-05 18:22
 * @desc 科目分类DAO
 */
@Mapper
public interface ClassifyDao {

    /**
     * 保存分类到数据库
     * @param classify
     * @return
     */
    @InsertProvider(type = ClassifyProvider.class, method = "save")
    @Options(useGeneratedKeys = true)
    int save(Classify classify);

    /**
     * 根据id删除分类
     * @param classifyId
     * @return
     */
    @DeleteProvider(type = ClassifyProvider.class, method = "deleteById")
    int deleteById(@Param("id") Integer classifyId);

    /**
     * 更新分类
     * @param classify
     * @return
     */
    @UpdateProvider(type = ClassifyProvider.class, method = "updateById")
    int updateById(Classify classify);

    /**
     * 根据id查分类信息
     * @param classifyId
     * @return
     */
    @SelectProvider(type = ClassifyProvider.class, method = "getClassifyById")
    @Results(id = "getSubject", value = {
            @Result(column = "classifyId", property = "subjects",
                    one = @One(select = "com.mjlf.hometeach.common.db.assit.SubjectDao.listSubjectByClassifyId",
                            fetchType = FetchType.LAZY)),
    })
    Classify getClassifyById(@Param("id") Integer classifyId);

    /**
     * 分解条件查询
     * @return
     */
    @SelectProvider(type = ClassifyProvider.class, method = "listClassifyByCondition")
    @ResultMap(value = "getSubject")
    List<Classify> listClassifyByCondition(Classify classify);
}
